package cn.tedu.micro.demo.headers;

import cn.tedu.micro.demo.client.RabbitChannelManager;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class HeadersDemo {

    @Test
    public void declareHeaders() throws Exception {
        //1.拿到客户端
        Channel channel= RabbitChannelManager.newChannel();
        //删除清空队列
        channel.queueDelete("queue1");
        channel.queueDelete("queue2");
        //2.声明3个队列
        channel.queueDeclare("queue1", false, false, false, null);
        channel.queueDeclare("queue2", false, false, false, null);
        //3.声明一个头交换机
        channel.exchangeDelete("headers_ex");
        channel.exchangeDeclare("headers_ex", BuiltinExchangeType.HEADERS);
        //4.声明绑定关系 上海 北京 天津
        Map<String,Object> queue1Head=new HashMap<String,Object>();
        queue1Head.put("x-match","any");
        queue1Head.put("name","王翠花");
        queue1Head.put("age",18);
        channel.queueBind("queue1","headers_ex","",queue1Head);
        Map<String,Object> queue2Head=new HashMap<String,Object>();
        queue2Head.put("x-match","all");
        queue2Head.put("name","王翠花");
        queue2Head.put("age",18);
        channel.queueBind("queue2","headers_ex","",queue2Head);
    }
}